import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets


import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

import '@/styles/index.scss' // global css
// index.js or main.js3
import './assets/iconfont/iconfont.css'
import App from './App'
import store from './store'
import router from './router'
import axios from 'axios'
import './utils/rem'
Vue.prototype.$axios = axios
Vue.config.productionTip = false
axios.defaults.baseURL = '/api'
import '@/icons' // iconz
import '@/permission' // permission control
import { baseBai } from "@/utils/baseBai"
import { http } from "@/utils/server"
import { baseYiBao } from "@/utils/baseYiBao"
import { _API } from './api/bai'

import { utilsB } from '@/utils/utilsB'
import ROLE_MAPS from '@/utils/role_maps'

// 或者
/**
 * If you don't want to use mock-server
 * you want to use mockjs for request interception
 * you can execute:
 *
 * import { mockXHR } from '../mock'
 * mockXHR()
 */
// set ElementUI lang to EN
console.log("role_maps", ROLE_MAPS)
Vue.use(ElementUI, { locale })
Vue.prototype._API = _API;
Vue.prototype.$utilsB = utilsB;
Vue.prototype.$http = http;
Vue.prototype.$baseBai = baseBai;
Vue.prototype.$baseYiBao = baseYiBao;
Vue.prototype.$ROLE_MAPS = ROLE_MAPS;

// 节流
// const on = Vue.prototype.$on

// Vue.prototype.$on = function (event, func) {
//   let previous = 0
//   let newFunc = func
//   if (event === 'click') {
//     newFunc = function () {
//       const now = new Date().getTime()
//       if (previous + 2000 <= now) {
//         func.apply(this, arguments)
//         previous = now
//       }
//     }
//   }
//   on.call(this, event, newFunc)
// }

// 防抖处理 -- 最后执行
const on = Vue.prototype.$on
Vue.prototype.$on = function(event, func) {
    let timer
    let newFunc = func
    if (event === 'click') {
        newFunc = function() {
            clearTimeout(timer)
            timer = setTimeout(function() {
                func.apply(this, arguments)
            }, 500)
        }
    }
    on.call(this, event, newFunc)
}
Vue.config.productionTip = false
    //浮点数押金运算
Vue.prototype.NumberAdd = function(arg1, arg2) {
        var r1, r2, m, n;
        try {
            r1 = arg1.toString().split(".")[1].length
        } catch (e) {
            r1 = 0
        }
        try {
            r2 = arg2.toString().split(".")[1].length
        } catch (e) {
            r2 = 0
        }
        m = Math.pow(10, Math.max(r1, r2))
        n = (r1 >= r2) ? r1 : r2;
        return ((arg1 * m + arg2 * m) / m).toFixed(n);
    },
    Vue.prototype.NumberSub = function(arg1, arg2) {
        var re1, re2, m, n;
        try {
            re1 = arg1.toString().split(".")[1].length;
        } catch (e) {
            re1 = 0;
        }
        try {
            re2 = arg2.toString().split(".")[1].length;
        } catch (e) {
            re2 = 0;
        }
        m = Math.pow(10, Math.max(re1, re2));
        n = (re1 >= re2) ? re1 : re2;
        return ((arg1 * m - arg2 * m) / m).toFixed(n);
    }
new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
})